package com.swufe.bmiapplication;

import androidx.appcompat.app.AppCompatActivity;

import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;

public class MainActivity extends AppCompatActivity implements View.OnClickListener{

    TextView out;
    EditText edit_weight;
    EditText edit_height;


    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        out = (TextView) findViewById(R.id.BMI);
        edit_weight = (EditText) findViewById(R.id.Height);
        edit_height = (EditText) findViewById(R.id.Weight);

        Button btn = (Button) findViewById(R.id.btn);
        btn.setOnClickListener( this);

    }

    @Override
    public void onClick(View v) {
        Log.i("main","onClick msg...");
        String str_height = edit_height.getText().toString();
        String str_weight = edit_weight.getText().toString();

        double h = 0.1;
        h = Double.parseDouble(str_height);
        double w = 0.1;
        w = Double.parseDouble(str_weight);
        
        Double BMI = w / (h*h);
        String result = String.format("%.2f", BMI);

        out.setText(String.valueOf(result));

    }
}